/*
 * Write code to reverse a C-style String.
 * (C-String means that "abcd" is represented as five characters, 
 * including the null character 
 */

public class Chapter1_2 {
//	public static void main(String []args)
//	{
//		Chapter1_2 test = new Chapter1_2();
//		test.reverseStr("abcdefg");
//	}
	
	//helper function
	public char[] CStringConverter(String _str)
	{
		int length = _str.length();
		char[] cstr = new char[length + 1];
		for(int i = 0; i < length; i++)
			cstr[i] = _str.charAt(i);
		cstr[length] = '\0';
		return cstr;
	}
	
	public void reverseStr(String _str)
	{
		char[] cstr = CStringConverter(_str);
		int length = cstr.length - 1;
		char tempChar;
		for(int i = 0; i < (int)(length/2); i++ )
		{
			tempChar = cstr[i];
			cstr[i] = cstr[length - i - 1];
			cstr[length - i - 1] = tempChar;
		}
		
		//print out
		for(int i = 0; i < cstr.length; i++)
		{
			System.out.print(cstr[i]);
		}
		System.out.println();
	}
}
